<?php
header("Content-type: text/html; charset= UTF-8");
require_once '../../includes/global.php';
header("Content-type: text/html; charset= UTF-8");
//error_reporting(E_ALL);

//Jc('g');
//配xajax

//得到配置文件
$wcfg = Dga('wcfg', "web like '".$sitename."' and lg like '".$_SESSION[LG]."'");
$wcfg = json_decode($wcfg[wcfg], true);
$dcfg = Dga('dcfg', "id like '".$_GET[did]."'");
$dcfg = json_decode($dcfg[dcfg], true);
//Jc($dcfg);
/*
 * 排序更新
 */
if($_POST['act']==1 && $_POST['op']=='order'){
	foreach($_POST['order'] as $odK=>$odV){
		$order_new[$_GET['orderfield']]=$odV;
		Du($dcfg['name'],$order_new,"id",$odK);
	}
	Jt('-1',"更新成功",1.2);
	exit;
}
$_SESSION[$dcfg['name']] == '' && $_SESSION[$dcfg['name']] = '1';
$xuan = array ();
$yin = array ();
$search = array ();
$condition = array ();
$ban=array();
foreach ($dcfg[structure] as $dkey=>$dvalue) {
	//屏蔽
	if ($dvalue['ban']==1){
		$ban[]=$dkey;
	}
	//yinxuan
	switch($dvalue['show']) {
		case 1: {
				$xuan[$dkey] = $dvalue['COMMENT'];
				break;
			}
		case 2: {
				$yin[$dkey] = $dvalue['COMMENT'];
				break;
			}
		default: {
				break;
			}
	}
	//search
	switch($dvalue['search']) {
		case 1: {
				$search[$dkey] = $dvalue['COMMENT'];
				$_GET[$_GET['lg']][$dkey] != '' && $condition[$_GET['lg']] .= " and ".$dkey." like '%".$_GET[$_GET[lg]][$dkey]."%' ";
				break;
			}
		case 2: {
				$search[$dkey] = $dvalue['COMMENT'];
				$_GET[$_GET[lg]] != '' && $condition[$_GET['lg']] .= " and ".$dkey." like '%".$_GET[$_GET[lg]][$dkey]."%' ";
				break;
			}
		case 3: {
				$search[$dkey] = $dvalue['COMMENT'];
				sort($_GET[$_GET[lg]][$dkey]);
				$tseslec = implode(',', $_GET[$_GET[lg]][$dkey]);
				//Jc($_GET[$_GET[lg]][$dkey]);
				$tseslec != '' && $tseslec != '0' && $condition[$_GET['lg']] .= " and INSTR(".$dkey.",',".$tseslec.",')>0  ";
				break;
			}
		case 4:
			/***
			 * 专门给my97的时间搜索用的
			 * @var
			 */
				$search[$dkey] = $dvalue['COMMENT'];
				$cuo=strtotime($_GET[$_GET[lg]][$dkey]);//转为时间戳
				if($cuo!=''){
					$My97Start=strtotime(date("Y-m-d",$cuo));//开始时间
					$My97End=strtotime(date("Y-m-d",$cuo))+INT_DAY;//一天后的时间
					$_GET[$_GET[lg]] != '' && $condition[$_GET['lg']] .= " and ".$dkey." >= '".$My97Start."'  and ".$dkey." < '".$My97End."' ";
				}
				break;
		default: {
				break;
			}
	}
	//附加功能
	if ($dvalue['ftype'] == 'bind') {
		if($dvalue['filter']['open']==1 && $dvalue['filter']['data']!=''){
			$dvalue['filter']['COMMENT'] = $dvalue['COMMENT'];
			$bind_filter[$dkey] = $dvalue['filter'];
			$bind_filter_tmp=preg_split("/,|#/",$dvalue['filter']['data']);
			foreach($bind_filter_tmp as $bind_filter_tmp_v){
				$bind_filter_arr[] = $bind_filter_tmp_v;
			}
		}else{
			$bind[$dkey] = $dvalue['COMMENT'];
		}
	}
	//推荐属性
	if ($dvalue['ftype'] == 'recommend') {
		$recommend[$dkey] = $dvalue['COMMENT'];
		$dvalue['order']['comment'] = $dvalue['COMMENT'];
		if($dvalue['order']['open']==1){
			$order[$dkey]=$dvalue['order'];
		}
	}
	//分类式信息浏览
	if ($dvalue['ftype'] == 'dselect') {
		$fen = true;
	}
	//自定义的-龙
	if($dvalue['ftype']=='tuiBic'){
			$recommendbic[$dkey]=$dvalue['COMMENT'];
				}

	//浏览数值需要转换
	switch($dvalue['change']) {
		case 'yinyong': {
				$yinyong[] = $dkey;
				break;
			}
		case 'datetime': {
				$datetime[] = $dkey;
				break;
			}
		case 2: {
				$search[$dkey] = $dvalue['COMMENT'];
				$_GET[$_GET[lg]] != '' && $condition[$_GET['lg']] .= " and ".$dkey." like '%".$_GET[$_GET[lg]][$dkey]."%' ";
				break;
			}
		default: {
				break;
			}
	}

	//全局时间格式化
	if($dvalue['datetimeChange']==1){
		$datetimeChange[$dkey]['field']=$dkey;
		$datetimeChange[$dkey]['globalformat']=$dvalue['globalformat'];
	}

}
//Jc($order);

//Jc($dcfg);
//检测多语言屏蔽
if (array_key_exists($dcfg['name'], $wcfg['ping'])) {
	$wcfg['num'] = 1;
	$temp = $wcfg['lang'][$wcfg['ping'][$dcfg['name']]];
	unset ($wcfg['lang']);
	$wcfg['lang'][$wcfg['ping'][$dcfg['name']]] = $temp;
}
$wcfg=array();
$wcfg['prefix']='lm';
$wcfg['lang'][$_GET['lg']]='排序';
$wcfg['num']=1;

//开启用户信息分类功能
$noCheck=array();
//$noCheck=array('admin','root');//用户过渡表
//Jc($wcfg);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Prosperous JIMU</title>
        <?php
        echo $printXajax;
        ?>
        <link href="../css/mod.css" rel="stylesheet" type="text/css" />
		<script src="/jimu/My97/WdatePicker.js" type="text/javascript"></script>

        <!--<script type="text/javascript">parent.document.getElementById('loading').innerHTML = '正在加载UI组建...';</script>
        !-->
        <script language="javascript">
            if (top.location == self.location)
                alert('此路不通');
            window.close();
        </script>
        <script language="javascript">
            window.onload = function(){
                var str1 = "?";
                var links = document.getElementsByTagName("A")||document.all.tags("A");
                var total = links.length;
                for (i = 0; i < total; i++) {
                    var s = links[i].href.indexOf(str1);
                    if (s > 0) {
                        links[i].href = links[i].href + '&from=b&mid=<?php echo $_GET[mid];?>';
                    }
                    else {
                        links[i].href = links[i].href + '?from=b&mid=<?php echo $_GET[mid];?>';
                    }
                }
            }
        </script>
    </head>
    <body>
        <div id="container">
        <div id="title">
            <ul>
                <?php
                $i = 1;
				if (is_array($wcfg['lang'])) {
					foreach ($wcfg[lang] as $key=>$lg) {
						if ($i == 1) {
							$temp1 = "class=\"selectli".$i."\"";
							$temp2 = "class=\"selectspan".$i."\"";
						} else {
							$temp1 = "";
							$temp2 = "";
						}

						echo "<li id=\"tag".$i."\"><a href=\"###\" onclick=\"switchTag('tag".$i."','content".$i."');this.blur();\" ".$temp1."><span ".$temp2.">".$dcfg['title']."【".$lg."】</span></a></li>";
						$i++;
					}
                }
                ?>
            </ul>
<script type="text/javascript">
<!--
function switchTag(tag,content){
	var allnum=<?php echo $wcfg[num];?>;
	for(i=1; i <= allnum; i++)
	{
		if ("tag"+i==tag)
		{
			document.getElementById(tag).getElementsByTagName("a")[0].className="selectli"+i;
			document.getElementById(tag).getElementsByTagName("a")[0].getElementsByTagName("span")[0].className="selectspan"+i;
		}else{
			document.getElementById("tag"+i).getElementsByTagName("a")[0].className="";
			document.getElementById("tag"+i).getElementsByTagName("a")[0].getElementsByTagName("span")[0].className="";
		}
		if ("content"+i==content)
		{
			document.getElementById(content).className="";
		}else{
			document.getElementById("content"+i).className="hidecontent";
		}
		document.getElementById("content").className=content;
	}
}
//-->
</script>
        </div>
        <div id="content" class="content1">
        <div id="loading"></div>
        <?php
        $xhgs = 1;
	if (is_array($wcfg['lang'])) {
        foreach ($wcfg[lang] as $lgk=>$lgv) {
        	if ($xhgs == 1) {
        		echo " <div id=\"content".$xhgs."\" >";
        	} else {
        		echo "<div id=\"content".$xhgs."\" class=\"hidecontent\">";
        	}

        	echo "
        <!-- <fieldset><legend><img src='../img/find.gif' border='0'  style='display:left;vertical-align:middle;' ait='检索' /> 〖".$dcfg[title]."〗检索〖SEARCH〗</legend>";
        	//内容开始
        ?>
        <form action="l.php" method="get" enctype="multipart/form-data" id="vform">
            <?php
            //Jc('g');

			 foreach($search as $key => $value){
            	//屏蔽功能 
            	if(in_array($key,$ban)){
            		continue;
            	}
			 	echo "<span style=\"float:left;width:300px;\">";
			 	echo "<span style=\"float:left;width:80px;padding-top:6px;\">";
			 	$dcfg['structure'][$key]['ftype']($key,$lgk,0,0);
			 	echo "</span>";
				 echo ":&nbsp;";
				$dcfg['structure'][$key]['ftype']($key,$lgk,1,0,$_GET[$lgk][$key]);
				echo "</span>";
			 }
            ?>
            <input type="hidden" value="<?php echo $_GET['did'];?>" name='did'/><input type="hidden" value="<?php echo $_GET['bdb'];?>" name='bdb'/><input type="hidden" value="<?php echo $_GET['mid'];?>" name='mid'/><input type="hidden" value="b" name='from'/><input type="hidden" value="<?php echo $_GET['bdid'];?>" name='bdid'/><input type="hidden" value="<?php echo $lgk;?>" name='lg'/><input name="SEARCH" value="检索" type="submit" />
        </form>
        <br/>
        <br/>
        </fieldset>
         -->
        <br/>
        <form action="" method="post">
        <table width="100%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#999999" style="border-collapse: collapse">
            <tr>
            </tr>
            <!-- 表头 !-->
            <tr>
            </tr>
            <tr>
            	<td height='30' align='center'><b>排序</b></td>
                <?php
                foreach ($xuan as $key=>$value) {
	            	//屏蔽功能 
            		if(in_array($key,$ban)){
            			continue;
            		}
                	echo "<td height='30' align='center'>".$value."</td>";
                }
                ?>
                <td height='30' align='center'>
                    操作〖OPERATE〗
                </td>
            </tr>
            <?php
            
            $condition='';
            if ($_GET['full_table_order']!=1){
                /*
                 * 全表排序
                 */
                if ($_GET['bdb']!=''){
                    $condition=" and bdb={$_GET['bdb']}";
                }
                if ($_GET['bdid']!=''){
                    $condition.=" and bdid like '{$_GET['bdid']}'";
                }
                $condition.=" and sortid={$_GET['did']}";
            }
            //排序功能
            $condition.=" and {$_GET['orderfield']}!=0 order by {$_GET['orderfield']} {$_GET['order']}";
        
            $sql = "
            SELECT *
            FROM ".$wcfg['prefix']."_".$dcfg['name']." AS A
            where 1   and A.del!=1 and A.lg='{$lgk}' {$condition}  ";
            echo $dcfg['debug']==true||1?$sql:'';
            //数据
            mysql_query("Set Names '".DEFAULT_CHARSET."' ");
            $result = mysql_query($sql);
            while ($temp = mysql_fetch_array($result))
            {
            		
            		
            	//Jc($temp);
            	echo ' <tr onmouseover="this.style.background=\'#ABC7EC\'" onmouseout="this.style.background=\'#D1DEF1\'">  ';
            	echo "<td height='30' align='center'><input name='order[{$temp['id']}]' type='text' value='".$temp[$_GET['orderfield']]."' style='text-align:center;width:21px !important;border:1px solid #9c9c9c;' onfocus='this.select();'/></td>";
            	foreach ($xuan as $key=>$value) {
	            	//屏蔽功能 
            		if(in_array($key,$ban)){
            			continue;
            		}
	            	
            		if (in_array($key, $yinyong)) {
            			echo "<td height='30' align='center'>".(yinyong($key, 1, $temp[$key]))."</td>";
            		} elseif (in_array($key, $datetime)) {
            			echo "<td height='30' align='center'>".date("Y-m-d H:i:s", $temp[$key])."</td>";
            		} else {
            			if($key==$datetimeChange[$key]['field']){
            				$temp[$key]=date($datetimeChange[$key]['globalformat'],$temp[$key]);
            			}
            			echo "<td height='30' align='center'>".$temp[$key]."</td>";
            		}

            	}
            	//权限

            	//推荐
            	$tujian = '';


					/*推荐属性*/
            		foreach ($recommend as $rkey=>$rvalue) {
		            	//屏蔽功能 
	            		if(in_array($rkey,$ban)){
	            			continue;
	            		}

						if(is_array($dcfg['recommend']) && !in_array($rkey,$dcfg['recommend']) || 1){
            				$tujian .= ($temp[$rkey])?("<a  href='t.php?op=tui&did=".$dcfg['name']."&id=".$temp[id]."&zd=".$rkey."&v=0'  title='真〖".$rvalue."〗'><img src='../img/flag_".$dcfg['structure'][$rkey]['flag'].".gif' border='0' ait='真〖".$rvalue."〗'></a>"):
            				("<a  href='t.php?op=xiao&did=".$dcfg['name']."&id=".$temp[id]."&zd=".$rkey."&v=1'  title='假〖".$rvalue."〗'><img src='../img/flag_white.gif' border='0' ait='假〖".$rvalue."〗'></a>");
						}
            		}
            		echo "<td height='30' align='center'>";

					//是否可以修改
					if($dcfg['change']!=1 || in_array($_SESSION['userinfo']['user'],$noCheck)){
						if ($_GET['did']==2) {
								echo "
							<a href='#' title='编辑〖EDIT〗'><img src='../img/edit.gif' border='0' ait='编辑〖EDIT〗' onCLick=\"if(confirm('是否进入傻瓜配置?')){window.location='modify.php?did=".$temp['id']."';}else{window.location='c.php?did=".$_GET['did']."&gid=".$temp['gid']."&from=b&mid=".$_GET[mid]."';}\" /></a>";
						}else{
							echo "
							<a href='c.php?did=".$_GET['did']."&gid=".$temp['gid']."&from=b&mid=".$_GET[mid]."' title='编辑〖EDIT〗'><img src='../img/edit.gif' border='0' ait='编辑〖EDIT〗'></a>";
						}
					}

					//是否可以删除
					if($dcfg['del']!=1 || in_array($_SESSION['userinfo']['user'],$noCheck)){
						echo "
            			<a href='d.php?did=".$_GET['did']."&id=".$temp['id']."' onclick=\"return confirm('你确定要删除？删除后将无法恢复！')\" title='删除〖DELETE〗'><img src='../img/delete.gif' border='0' ait='删除〖DELETE〗'></a>";
					}

					//是否可以查看
					//if(!isset($dcfg['view']) || $dcfg['view']==1 || in_array($_SESSION['userinfo']['user'],$noCheck)){
					if($dcfg['view']!=1 || in_array($_SESSION['userinfo']['user'],$noCheck)){
						echo "
            			<a href='s.php?did=".$_GET['did']."&gid=".$temp['gid']."$isbdda3b' title='浏览〖LIST〗 title='查看【SHOW】'><img src='../img/page_html.gif' border='0' ait='查看【SHOW】'></a>";
					}
					/*
					//附属功能 
					//Jc($temp);
					$bind_had='';
					if($bind){
						$bind_had=1;
					}else{
						//Jc($temp);
						foreach($bind_filter as $bfkey=>$bfvalue){
			            	//屏蔽功能 
		            		if(in_array($bfkey,$ban)){
		            			continue;
		            		}
							if(in_array($temp[$bfvalue['field']],$bind_filter_arr)){
								$bind_had=1;
							}
						}
					}
					if($bind_had){
						echo "<a  href='#' onClick=\"showorhidden(document.getElementById('p".$temp[id]."'))\" title='扩展〖EXTENSIONS〗'><img src='../img/list_extensions.gif' border='0' ait='扩展〖EXTENSIONS〗'></a>";
					}
            		*/
            		echo "{$tujian}</td></tr>";
					/*echo "
            		".(($bind)?("<a  href='#' onClick=\"showorhidden(document.getElementById('p".$temp[id]."'))\" title='扩展〖EXTENSIONS〗'><img src='../img/list_extensions.gif' border='0' ait='扩展〖EXTENSIONS〗'></a>"):
            			("")).$tujian."
            		</td>";*/

            		if ($bind_had) {
						echo "<tbody name='q".$temp[id]."' id='p".$temp[id]."' style=\"display:none;\">
								  <tr><td height='20' colspan=16 bgColor=#ffffff align='right'>
									<div  style=\"margin-right:20px;\">";
						/*附属[1]*/
						foreach ($bind as $bkey=>$bvalue) {
			            	//屏蔽功能 
		            		if(in_array($bkey,$ban)){
		            			continue;
		            		}

							/*echo $bvalue."【
								<a href='c.php?did=".$dcfg['structure'][$bkey]['did']."&bdb=".$_GET['did']."&bdid=".$temp[gid]."&comment=".urlencode($bvalue['COMMENT'])."' title='添加".$dvalue['COMMENT']."【AddBind】'><img src='../img/image_new.gif' border='0' ait='添加".$dvalue."【AddBind】'></a>
								<a href='###' onclick='window.parent.tab.add({\"id\":\"edit_".$temp[gid]."\",\"title\":\"附属查看\",closable:true,html:\"<iframe scrolling=\'auto\' frameborder=\'0\' width=\'100%\' height=\'100%\' src=\'/admin/mod/l.php?did=".$dcfg['structure'][$bkey]['did']."&bdb=".$_GET['did']."&bdid=".$temp[gid]."&comment=".urlencode($dvalue['COMMENT'])."\'></iframe>\"});window.parent.tab.setActiveTab(\"edit_".$temp[gid]."\");' title='显示".$dvalue['COMMENT']."【Listbind】'><img src='../img/image.gif' border='0' ait='显示".$dvalue['COMMENT']."【Listbind】'></a>
								】";*/
							echo $bvalue;
							//$bvalue['COMMENT']=urlencode($bvalue['COMMENT']);
							echo <<<EQT
							【
								<a href='###' onclick='window.parent.tab.add({"id":"add_{$temp[gid]}","title":"附属[{$bvalue}]添加",closable:true,html:"<iframe scrolling=\"auto\" frameborder=\"0\" width=\"100%\" height=\"100%\" src=\"/admin/mod/c.php?did={$dcfg['structure'][$bkey]['did']}&bdb={$_GET['did']}&bdid={$temp[gid]}&comment={$bvalue['COMMENT']}&from=b&mid={$_GET['mid']}\"></iframe>"});window.parent.tab.setActiveTab("add_{$temp[gid]}");'  title='添加{$dvalue['COMMENT']}【AddBind】'><img src='../img/image_new.gif' border='0' ait='添加{$dvalue}【AddBind】'></a>
								<a href='###' onclick='window.parent.tab.add({"id":"view_{$temp[gid]}","title":"附属[{$bvalue}]查看",closable:true,html:"<iframe scrolling=\"auto\" frameborder=\"0\" width=\"100%\" height=\"100%\" src=\"/admin/mod/l.php?did={$dcfg['structure'][$bkey]['did']}&bdb={$_GET['did']}&bdid={$temp[gid]}&comment={$dvalue['COMMENT']}&from=b&mid={$_GET['mid']}\"></iframe>"});window.parent.tab.setActiveTab("view_{$temp[gid]}");' title='显示{$dvalue['COMMENT']}【Listbind】'><img src='../img/image.gif' border='0' ait='显示{$dvalue['COMMENT']}【Listbind】'></a>
								】
EQT;

						}
						/*附属[2]*/
						foreach ($bind_filter as $bkey=>$bvalue) {
			            	//屏蔽功能 
		            		if(in_array($bkey,$ban)){
		            			continue;
		            		}
		            		if(in_array($temp[$bvalue['field']],preg_split("/,|#/",$bvalue['data']))){
								echo $bvalue['COMMENT'];
								echo <<<EQT
								【
									<a href='###' onclick='window.parent.tab.add({"id":"add_{$temp[gid]}","title":"附属[{$bvalue['COMMENT']}]添加",closable:true,html:"<iframe scrolling=\"auto\" frameborder=\"0\" width=\"100%\" height=\"100%\" src=\"/admin/mod/c.php?did={$dcfg['structure'][$bkey]['did']}&bdb={$_GET['did']}&bdid={$temp[gid]}&comment={$bvalue['COMMENT']}&from=b&mid={$_GET['mid']}\"></iframe>"});window.parent.tab.setActiveTab("add_{$temp[gid]}");'  title='添加{$bvalue['COMMENT']}【AddBind】'><img src='../img/image_new.gif' border='0' ait='添加{$dvalue['COMMENT']}【AddBind】'></a>
									<a href='###' onclick='window.parent.tab.add({"id":"view_{$temp[gid]}","title":"附属[{$bvalue['COMMENT']}]查看",closable:true,html:"<iframe scrolling=\"auto\" frameborder=\"0\" width=\"100%\" height=\"100%\" src=\"/admin/mod/l.php?did={$dcfg['structure'][$bkey]['did']}&bdb={$_GET['did']}&bdid={$temp[gid]}&comment={$bvalue['COMMENT']}&from=b&mid={$_GET['mid']}\"></iframe>"});window.parent.tab.setActiveTab("view_{$temp[gid]}");' title='显示{$bvalue['COMMENT']}【Listbind】'><img src='../img/image.gif' border='0' ait='显示{$bvalue['COMMENT']}【Listbind】'></a>
									】
EQT;

							}
						}
						
						
						
									echo "</div>
								</td></tr></tbody>
						";
					}

            		}
            		mysql_free_result($result);

            ?>
        </table>
		<input name="op" type="hidden"  value="order"   />
		<input name="act" type="hidden"  value="1"   />
		<input name="did" type="hidden"  value="<?php echo $_REQUEST[did];?>"   />
		<input name="from" type="hidden"  value="b"   />
		<input name="mid" type="hidden"  value="<?php echo $_REQUEST[mid];?>"   />
        <div style="padding-top:10px;text-align:center;"><input type="submit" value="提交 " /></div>
        </form>
        <div align="center">
        </div>
        <?php
        $xhgs++;
        echo "</div>";
        }
	}
        ?>
    </div>
    </body>
    <script language="javascript">
        function uptag(tagid)
        {
        //document.getElementById('loading').innerHTML="<table><tr nowrap=\"nowrap\" class=\"firstalt\"><td colspan=2><img src=\"/includes/sysimg/loading.gif\"/></td></tr></table>";
        //xajax_updatetag(tagid,'<?php echo $dcfg['name'];?>');
        }
        switchTag('tag<?php echo $_SESSION[$dcfg['name']];?>','content<?php echo $_SESSION[$dcfg['name']];?>');
        function showorhidden(nodeObject){
              if (nodeObject.style.display == '' || nodeObject.style.display ==
        'block') {
                nodeObject.style.display = 'none';
              } else {
                nodeObject.style.display = '';
              }
            }
    </script>
</html>
